<%@ page language="java"
	import="cn.com.wxd.util.RequestUtil,cn.com.wxd.common.PageInfo"
	pageEncoding="utf-8"%>
<%
	PageInfo pageInfo = (PageInfo) request.getAttribute("page");
	if(pageInfo==null){
		return;
	}
	String id = RequestUtil.getParameter(request, "caid");
	if(id.trim().equals("")){
		id = "-1";
	}
	String ajaxFunctionName = RequestUtil.getParameter(request, "ajaxFunction");
%>

<style type="text/css">
.current,#info {
	border: 1px solid #DDD;
	background: #F2F2F2;
	display: inline-block;
	margin: 1px;
	text-decoration: none;
	font-size: 12px;
	width: 15px;
	height: 15px;
	text-align: center;
	line-height: 15px;
	color: #0000;
	padding: 1px 2px;
}

#setpage{
	  text-align: center;
}
.current {
	border: 1px solid #83E7E4;
	background: #DFF9F8;
	margin: 1px;
	color: #27CBC7;
}

#info {
	width: auto;
}
</style>


<div id="setpage"></div>

<script type="text/javascript">
	var totalpage, pagesize, cpage, count, outstr;
	//初始化
	cpage = <%=pageInfo.getPageIndex()%>;
	totalpage = <%=pageInfo.getPageCount()%>;
	pagesize = <%=pageInfo.getPageSize()%>;
	outstr = "";
	function gotopage(target) {
		cpage = target; //把页面计数定位到第几页
		setpage();
		<%=ajaxFunctionName %>('<%=id%>',target);
		//reloadpage(target);    //调用显示页面函数显示第几页,这个功能是用在页面内容用ajax载入的情况
	}
	function setpage() {
		if (totalpage <= 10) { //总页数小于十页
			for (count = 1; count <= totalpage; count++) {
				if (count != cpage) {
					outstr = outstr
							+ "<a id='paggingA' href='javascript:gotopage(" + count + ")' >" + count + "</a>";

				} else {
					outstr = outstr + "<span class='current' >" + count
							+ "</span>";
				}
			}
		}
		if (totalpage > 10) { //总页数大于十页
			if (parseInt((cpage - 1) / 10) == 0) {
				for (count = 1; count <= 10; count++) {
					if (count != cpage) {
						outstr = outstr
								+ "<a id='paggingA' href='javascript:gotopage("+ count + ")' >" + count + "</a>";
					} else {
						outstr = outstr + "<span class='current'>" + count + "</span>";
					}
				}
				outstr = outstr
						+ "<a id='paggingA' href='javascript:gotopage("+ count + ")' > 》 </a>";
			} else if (parseInt((cpage - 1) / 10) == parseInt(totalpage / 10)) {
				outstr = outstr
						+ "<a id='paggingA' " +
					"href='javascript:gotopage("+ (parseInt((cpage - 1) / 10) * 10) + ")' >《</a>";
				for (count = parseInt(totalpage / 10) * 10 + 1; count <= totalpage; count++) {
					if (count != cpage) {
						outstr = outstr
								+ "<a id='paggingA' href='javascript:gotopage("+ count + ")' >" + count + "</a>";
					} else {
						outstr = outstr + "<span class='current'>" + count + "</span>";
					}
				}
			} else {
				outstr = outstr
						+ "<a id='paggingA' " +
					"href='javascript:gotopage(" + (parseInt((cpage - 1) / 10) * 10) + ")' >《</a>";
				for (count = parseInt((cpage - 1) / 10) * 10 + 1;
					 count <= parseInt((cpage - 1) / 10) * 10 + 10;
					 count++) {
					if (count != cpage) {
						outstr = outstr
								+ "<a id='paggingA' href='javascript:gotopage("+ count + ")' >" + count + "</a>";
					} else {
						outstr = outstr + "<span class='current'>" + count
								+ "</span>";
					}
				}
				outstr = outstr
						+ "<a id='paggingA' href='javascript:gotopage("+ count + ")' > 》 </a>";
			}
		}
		document.getElementById("setpage").innerHTML = "<span id='info'>"
				+ cpage + "/" + totalpage + "<\/span>" + outstr;
		outstr = "";
	}
	setpage(); //调用分页
</script>
